package lei.g_java数组;

import javax.print.attribute.standard.PDLOverrideSupported;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @className: ArraysExample
 * @author: xl
 * @date: 2025/3/1 15:07
 * @Version: 1.0
 * @description:
 */

public class ArraysExample {
    public static void main(String[] args) {
        // 声明并初始化数组
        int[] intArray = new int[3];       // 固定长度数组
        intArray[0] = 10;
        intArray[1] = 20;
        intArray[2] = 30;

        // 直接初始化
        String[] strArray = {"Apple", "Banana", "Cherry"};

        Arrays.sort(intArray);
        System.out.println(Arrays.toString(intArray));

        List<Integer> integerList=Arrays.stream(intArray).boxed().collect(Collectors.toList());

        Collections.reverse(integerList);
        System.out.println(integerList);




        // 遍历数组
        for (int i = 0; i < intArray.length; i++) {
            System.out.println(intArray[i]);
        }

        // 增强 for 循环
        for (String fruit : strArray) {
            System.out.println(fruit);
        }
    }
}

